function handles = array2Dplot(handles)
% array2Dplot
%
% private version for mapAnalysis2p0
%
% Editing:
% gs april 2005
% ------------------------------------------------------

% TODO: fix text display of map name

% initialize some variables
array = handles.data.map.mapActive.bsArray;
[rows,cols] = size(array);
totalTime = (rows-1)/handles.data.acq.sampleRate;
xTimeAxis = linspace(0, totalTime, rows)'; 
traceAxis = [1:cols];

% set up the figure
x = .17; y = .08; w = .7; h = .7; 
figure('Units', 'normalized', 'Position', [x y w h], 'Name', 'array2Dplot', ...
    'NumberTitle', 'off', 'Color', 'w', 'DoubleBuffer', 'on');
subplotRows = 5; subplotCols = 4; plotnum = 0;

% polarity stuff -- gs 2006 12 02
if strcmp(handles.data.analysis.eventPolaritySyn, 'down')
    plotPolarityFactor = 1;
elseif strcmp(handles.data.analysis.eventPolaritySyn, 'up')
    plotPolarityFactor = -1;
end

% Laser intensity
plotnum = plotnum+1;
try
    hsub(plotnum) = subplot(subplotRows,subplotCols,plotnum);
    X = 1:length(handles.data.map.mapActive.laserIntensity);
    plot(X, handles.data.map.mapActive.laserIntensity, 'c-');
    set(gca, 'YLim', [0 max(get(gca, 'YLim'))], 'XLim', [0 max(X)]);
    xlabel('Trace');
    ylabel('mW');
    legend('laser', 0);
catch
    disp('array2Dplot: no laser intensity data available to plot');
end

% Rs, Rm
plotnum = plotnum+1;
hsub(plotnum) = subplot(subplotRows,subplotCols,plotnum);

if get(handles.chkWithRsRm, 'Value');
    try
        RCaxis = 1:length(handles.data.map.mapActive.rseries);
        RCaxis = (RCaxis - 1) * handles.data.analysis.RsSkipVal;
        plot(RCaxis, handles.data.map.mapActive.rseries, 'b-', ...
            RCaxis, handles.data.map.mapActive.rmembrane, 'g-');
        set(gca, 'XLim', [0 max(RCaxis)], 'YLim', [0 max(get(gca, 'YLim'))]);
        xlabel('Trace');
        ylabel('Rs (Mohm), Rm (Mohm)');
        legend('Rs', 'Rm', 0);
    catch
        disp('array2Dplot: unable to plot Rs data');
    end
else
    set(gca, 'Visible', 'off');
end

plotnum = plotnum+1;

% image of slice (in mapping position) -----------------------
plotnum = plotnum+1;
hsub(plotnum) = subplot(subplotRows,subplotCols,plotnum);
handles.data.analysis.hSliceImg = imagesc(handles.data.image.img);
daspect([1 1 1]);
% % set(himg, 'ButtonDownFcn', 'addSliceImage');
% set(gca, 'ButtonDownFcn', 'addSliceImage');
% title('Click to upload an image');
title(handles.data.image.imgName);
xrange = handles.data.acq.imageXrange;
yrange = handles.data.acq.imageYrange;
set(handles.data.analysis.hSliceImg, ...
    'XData', [-xrange/2 xrange/2], 'YData', [-yrange/2 yrange/2]);
axis tight;
% -----------------------------------------------------------

plotnum = plotnum+1;

% AMPLITUDE histogram *****************************

% obtain map of direct responses to exclude them from the histograms
directMap = handles.data.map.mapActive.mapDataArray(:,:,3);
directMap(directMap~=0) = NaN;
directMap(directMap==0) = 1; % ends up with NaNs at direct sites, 1's everywhere else

% histo params
leftLim = -9;
binWidth = .5;
rightLim = 74;
histoEdges = [-inf  (leftLim:binWidth:rightLim)  inf];
histoEdges2 = [leftLim-1*binWidth:binWidth:rightLim+1*binWidth];

% for each baseline and synaptic map, obtain the histograms of the data
n=1;    
% histo of the baseline window data
b = handles.data.map.mapActive.mapDataArray(:,:,13);
b = b.*directMap; % convert directs to NaNs
c = reshape(b, 1, numel(b)); % vectorize
baselineData(n, :) = c(~isnan(c)); % exclude NaNs
baselineN(n, :) = histc(baselineData(n, :), histoEdges);
%
% use the baseline noise level to generate a thresholded binary map of responses
baselineSD(n) = std(baselineData(n, :));
d = handles.data.map.mapActive.mapDataArray(:,:,14) > 2 * baselineSD(n); % 0 = null, 1 = synaptic response
d = d.*directMap;           % NaN = direct response
d(isnan(d))=-inf;           % NaN => inf for plotting
d = -d;

% histo of the synaptic window data 
s = handles.data.map.mapActive.mapDataArray(:,:,14);
s = s.*directMap;
c = reshape(s, 1, numel(s));
synapticData(n, :) = c(~isnan(c));
synapticN(n, :) = histc(synapticData(n, :), histoEdges);

plotnum = plotnum+1;
hsub(plotnum) = subplot(subplotRows,subplotCols,plotnum);
h = bar(histoEdges2, baselineN, 'histc');
set(h, 'FaceColor', 'k', 'LineStyle', 'none');
hold on;
h = bar(histoEdges2, synapticN, 'histc');
set(h, 'FaceColor', 'none', 'EdgeColor', 'r', 'LineWidth', [1]);
set(gca, 'XLim', [-15 80]);
xlabel('Amplitude (pA)');
ylabel('N');
legend('baseline', 'synaptic');
% legend boxoff;

% binarized/thresholded map (from amplitude histogram, 2SDs)
plotnum = plotnum+1;
hsub(plotnum) = subplot(subplotRows,subplotCols,plotnum);
himage = imagesc(d);
set(gca, 'CLim', [-1 0.03], 'PlotBoxAspectRatio', [1 1 1], 'Visible', 'off');

% LATENCY histogram *************************

plotnum = plotnum+1;
hsub(plotnum) = subplot(subplotRows,subplotCols,plotnum);

try
    % data for histogram -- from "All, Onset" array -- i.e., from genOnset map below
    if strcmp(handles.data.analysis.eventPolaritySyn, 'down')
        %     if ~handles.data.analysis.responsesInvertedFlag
        genMap = handles.data.map.mapActive.mapDataArray(:,:,10);
    else
        genMap = handles.data.map.mapActive.mapDataArray(:,:,12);
    end
    genMap(genMap==0) = inf;
    result = genMap;
    result(result==0) = inf;
    
    % histo params
    leftLim = 0;
    binWidth = .001;
    rightLim = handles.data.analysis.synapticWindow;
    histoEdges = [leftLim : binWidth : rightLim];
    
    % for each baseline and synaptic map, obtain the histograms of the data
    % n=1;    
    % histo of the baseline window data
    b = result;
    b(b == inf) = NaN;
    c = reshape(b, 1, numel(b)); % vectorize
    histoData = c(~isnan(c)); % exclude NaNs
    % histoData
    % histoEdges
    % size(histoData)
    % size(histoEdges)
    histoN = histc(histoData, histoEdges);
    
    h = bar(histoEdges, histoN, 'histc');
    set(h, 'FaceColor', 'r', 'LineStyle', 'none');
    set(gca, 'XLim', [leftLim rightLim]);
    xlabel('Onset latency (sec)');
    ylabel('Number');
    edEnd = handles.data.analysis.directWindow;
    hline = line([edEnd edEnd], [min(get(gca,'YLim')) max(get(gca,'YLim'))], ...
        'Color', 'b', 'LineStyle', ':'); 
    handles.data.map.mapStack.mapStackLatHistoEdges = histoEdges';
    if isempty(handles.data.map.mapStack.mapStackLatHistoN)
        handles.data.map.mapStack.mapStackLatHistoN = histoN';
    else
        handles.data.map.mapStack.mapStackLatHistoN = [handles.data.map.mapStack.mapStackLatHistoN histoN'];
    end
catch
    disp('No valid data for histogram.');
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MAP IMAGES - GENERAL SETTINGS
% % lens = state.uncaging.analysis.lens;
% % switch lens
% % case '10x Water'
% %     magFac = 375;
% % case '4x Air'
% %     magFac = 750;
% % end
[sizeX sizeY z] = size(handles.data.map.mapActive.mapDataArray(:,:,1));
magFacX = (handles.data.map.mapActive.mapSpacing * (sizeX-1))/2;
magFacY = (handles.data.map.mapActive.mapSpacing * (sizeY-1))/2;
plotNameTxtPos = [0 1.05];
colorBarTxtPos = [1.13 -.08];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



% SYNAPTIC + DIRECT WINDOW PLOTS *****************************************
% plot of all traces, superimposed
plotnum = plotnum+1;
hsub(plotnum) = subplot(subplotRows,subplotCols,plotnum);
plot(xTimeAxis, array);
set(gca, 'XLim', [0 max(xTimeAxis)]);
xlabel('Seconds');
ylabel('Amplitude');
stimOn = handles.data.analysis.stimOn;
line([stimOn stimOn], [min(get(gca,'YLim')) max(get(gca,'YLim'))], 'LineStyle', '-'); 
edEnd = stimOn + handles.data.analysis.directWindow;
line([edEnd edEnd], [min(get(gca,'YLim')) max(get(gca,'YLim'))], 'LineStyle', '-');
synEnd = stimOn + handles.data.analysis.synapticWindow;
line([synEnd synEnd], [min(get(gca,'YLim')) max(get(gca,'YLim'))], 'LineStyle', '-');

% genMin (or genMax) map
plotnum = plotnum+1;
hsub(plotnum) = subplot(subplotRows,subplotCols,plotnum);
if strcmp(handles.data.analysis.eventPolaritySyn, 'down')
    mapPlane = 5;  % genMin
else
    mapPlane = 11; % genMax
end
genMap = handles.data.map.mapActive.mapDataArray(:,:,mapPlane);
result = genMap;
result(result==0) = plotPolarityFactor * inf;;
imagesc(result, 'XData', [-magFacX magFacX], 'YData', [-magFacY magFacY]);
% lowerLim = min(min(result));
lowerLim = min(min(result(result>-inf)));
upperLim = max(max(result(result<inf)));
upperLimTweaked = upperLim + 0.02*(abs(upperLim-lowerLim));
set(gca, 'CLim', [lowerLim upperLimTweaked]);
set(gca, 'PlotBoxAspectRatio', [1 1 1]);
xlabel('micrometers');
ylabel('micrometers');
text(plotNameTxtPos(1), plotNameTxtPos(2),'Peak', ...
    'Units', 'Normalized', 'FontWeight', 'Bold');
colorbar('vert');
text(colorBarTxtPos(1), colorBarTxtPos(2),'pA', 'Units', 'Normalized');

% genMean map
plotnum = plotnum+1;
hsub(plotnum) = subplot(subplotRows,subplotCols,plotnum);
genMap = handles.data.map.mapActive.mapDataArray(:,:,9);
result = genMap;
result(result==0) = plotPolarityFactor * inf;;
imagesc(result, 'XData', [-magFacX magFacX], 'YData', [-magFacY magFacY]);
% lowerLim = min(min(result));
lowerLim = min(min(result(result>-inf)));
upperLim = max(max(result(result<inf)));
upperLimTweaked = upperLim + 0.02*(abs(upperLim-lowerLim));
set(gca, 'CLim', [lowerLim upperLimTweaked]);
set(gca, 'PlotBoxAspectRatio', [1 1 1]);
xlabel('micrometers');
text(plotNameTxtPos(1), plotNameTxtPos(2),'Mean', ...
    'Units', 'Normalized', 'FontWeight', 'Bold');
colorbar('vert');
text(colorBarTxtPos(1), colorBarTxtPos(2),'pA', 'Units', 'Normalized');

% genOnset map
plotnum = plotnum+1;
hsub(plotnum) = subplot(subplotRows,subplotCols,plotnum);
if strcmp(handles.data.analysis.eventPolaritySyn, 'down')
    genMap = handles.data.map.mapActive.mapDataArray(:,:,10);
else
    genMap = handles.data.map.mapActive.mapDataArray(:,:,12);
end
genMap(genMap==0) = inf;
result = genMap;
result(result==0) = plotPolarityFactor * inf;;
imagesc(result, 'XData', [-magFacX magFacX], 'YData', [-magFacY magFacY]);
% lowerLim = min(min(result));
lowerLim = min(min(result(result>-inf)));
upperLim = max(max(result(result<inf)));
upperLimTweaked = upperLim + 0.02*(abs(upperLim-lowerLim));
try
    set(gca, 'CLim', [lowerLim upperLimTweaked]);
catch
    disp('array2Dplot: problem setting CLim');
end
set(gca, 'PlotBoxAspectRatio', [1 1 1]);
xlabel('micrometers');
text(plotNameTxtPos(1), plotNameTxtPos(2),'Onset', ...
    'Units', 'Normalized', 'FontWeight', 'Bold');
try
    hcb = colorbar('vert');
    text(colorBarTxtPos(1), colorBarTxtPos(2), '(sec)', 'Units', 'Normalized');
catch
    disp('array2Dplot: unable to make colormap for image.');
end

% SYNAPTIC WINDOW PLOTS *****************************************
% plot of synaptic response traces, superimposed
plotnum = plotnum+1;
hsub(plotnum) = subplot(subplotRows,subplotCols,plotnum);
plot(xTimeAxis(900:2100, :), array(900:2100, find(~handles.data.map.mapActive.edBinary)));
set(gca, 'XLim', [.09 .21]);
xlabel('Seconds');
ylabel('Amplitude');
stimOn = handles.data.analysis.stimOn;
line([stimOn stimOn], [min(get(gca,'YLim')) max(get(gca,'YLim'))], 'LineStyle', '-'); 
edEnd = stimOn + handles.data.analysis.directWindow;
line([edEnd edEnd], [min(get(gca,'YLim')) max(get(gca,'YLim'))], 'LineStyle', '-');
synEnd = stimOn + handles.data.analysis.synapticWindow;
line([synEnd synEnd], [min(get(gca,'YLim')) max(get(gca,'YLim'))], 'LineStyle', '-');

% genMin (or genMax) map
plotnum = plotnum+1;
hsub(plotnum) = subplot(subplotRows,subplotCols,plotnum);
if strcmp(handles.data.analysis.eventPolaritySyn, 'down')
    mapPlane = 5;  % genMin
else
    mapPlane = 11; % genMax
end
genMap = handles.data.map.mapActive.mapDataArray(:,:,mapPlane);
edMap = handles.data.map.mapActive.mapDataArray(:,:,3)==0;
edLessGenMap = genMap.*edMap;
result = edLessGenMap;
result(result==0) = plotPolarityFactor * inf;;
imagesc(result, 'XData', [-magFacX magFacX], 'YData', [-magFacY magFacY]);
% lowerLim = min(min(result));
lowerLim = min(min(result(result>-inf)));
upperLim = max(max(result(result<inf)));
%     if sum(sum(result~=inf)) ~= 0
if lowerLim ~= upperLim & ~isempty(upperLim)
    upperLimTweaked = upperLim + 0.02*(abs(upperLim-lowerLim));
    set(gca, 'CLim', [lowerLim upperLimTweaked]);
else
    set(gca, 'CLim', [0 inf]);
end
set(gca, 'PlotBoxAspectRatio', [1 1 1]);
xlabel('micrometers');
ylabel('micrometers');
text(plotNameTxtPos(1), plotNameTxtPos(2),'Peak', ...
    'Units', 'Normalized', 'FontWeight', 'Bold');
try
    colorbar('vert');
    text(colorBarTxtPos(1), colorBarTxtPos(2),'pA', 'Units', 'Normalized');
catch
    disp('array2Dplot: unable to make colorbar for image.');
end

% genMean map
plotnum = plotnum+1;
hsub(plotnum) = subplot(subplotRows,subplotCols,plotnum);
genMap = handles.data.map.mapActive.mapDataArray(:,:,9);
edMap = handles.data.map.mapActive.mapDataArray(:,:,3)==0;
edLessGenMap = genMap.*edMap;
result = edLessGenMap;
result(result==0) = plotPolarityFactor * inf;;
imagesc(result, 'XData', [-magFacX magFacX], 'YData', [-magFacY magFacY]);
% lowerLim = min(min(result));
lowerLim = min(min(result(result>-inf)));
upperLim = max(max(result(result<inf)));
if lowerLim ~= upperLim & ~isempty(upperLim)
    upperLimTweaked = upperLim + 0.02*(abs(upperLim-lowerLim));
    set(gca, 'CLim', [lowerLim upperLimTweaked]);
else
    set(gca, 'CLim', [0 inf]);
end
set(gca, 'PlotBoxAspectRatio', [1 1 1]);
xlabel('micrometers');
text(plotNameTxtPos(1), plotNameTxtPos(2),'Mean', ...
    'Units', 'Normalized', 'FontWeight', 'Bold');
try
    colorbar('vert');
    text(colorBarTxtPos(1), colorBarTxtPos(2),'pA', 'Units', 'Normalized');
catch
    disp('array2Dplot: unable to make colorbar for image.');
end

% genOnset map
plotnum = plotnum+1;
hsub(plotnum) = subplot(subplotRows,subplotCols,plotnum);
if strcmp(handles.data.analysis.eventPolaritySyn, 'down')
    genMap = handles.data.map.mapActive.mapDataArray(:,:,10);
else
    genMap = handles.data.map.mapActive.mapDataArray(:,:,12);
end
edMap = handles.data.map.mapActive.mapDataArray(:,:,3)==0;
edLessGenMap = genMap.*edMap;
edLessGenMap(edLessGenMap==0) = inf;
result = edLessGenMap;
result(result==0) = plotPolarityFactor * inf;;
imagesc(result, 'XData', [-magFacX magFacX], 'YData', [-magFacY magFacY]);
% lowerLim = min(min(result));
lowerLim = min(min(result(result>-inf)));
upperLim = max(max(result(result<inf)));
if lowerLim ~= upperLim & ~isempty(upperLim)
    upperLimTweaked = upperLim + 0.02*(abs(upperLim-lowerLim));
    set(gca, 'CLim', [lowerLim upperLimTweaked]);
else
    set(gca, 'CLim', [0 inf]);
end
set(gca, 'PlotBoxAspectRatio', [1 1 1]);
xlabel('micrometers');
text(plotNameTxtPos(1), plotNameTxtPos(2),'Onset', ...
    'Units', 'Normalized', 'FontWeight', 'Bold');
try
    colorbar('vert');
    text(colorBarTxtPos(1), colorBarTxtPos(2), '(sec)', 'Units', 'Normalized');
catch
    disp('array2Dplot: unable to make colorbar for image.');
end

% DIRECT WINDOW PLOTS *****************************************
% plot of direct response traces, superimposed
plotnum = plotnum+1;
if ~isempty(find(handles.data.map.mapActive.edBinary));
    hsub(plotnum) = subplot(subplotRows,subplotCols,plotnum);
    plot(xTimeAxis(900:2100, :), array(900:2100, find(handles.data.map.mapActive.edBinary)));
    set(gca, 'XLim', [.09 .21]);
    xlabel('Seconds');
    ylabel('Amplitude');
    stimOn = handles.data.analysis.stimOn;
    line([stimOn stimOn], [min(get(gca,'YLim')) max(get(gca,'YLim'))], 'LineStyle', '-'); 
    edEnd = stimOn + handles.data.analysis.directWindow;
    line([edEnd edEnd], [min(get(gca,'YLim')) max(get(gca,'YLim'))], 'LineStyle', '-');
    synEnd = stimOn + handles.data.analysis.synapticWindow;
    line([synEnd synEnd], [min(get(gca,'YLim')) max(get(gca,'YLim'))], 'LineStyle', '-');
end

% genMin map
plotnum = plotnum+1;
if ~isempty(find(handles.data.map.mapActive.edBinary));
    hsub(plotnum) = subplot(subplotRows,subplotCols,plotnum);
    if strcmp(handles.data.analysis.eventPolaritySyn, 'down')
        mapPlane = 5;  % genMin
    else
        mapPlane = 11; % genMax
    end
    genMap = handles.data.map.mapActive.mapDataArray(:,:,mapPlane);
    edMap = handles.data.map.mapActive.mapDataArray(:,:,3)==0;
    edGenMap = genMap.*~edMap;
    result = edGenMap;
    result(result==0) = plotPolarityFactor * inf;;
    imagesc(result, 'XData', [-magFacX magFacX], 'YData', [-magFacY magFacY]);
    % lowerLim = min(min(result));
    lowerLim = min(min(result(result>-inf)));
    upperLim = max(max(result(result<inf)));
    %     if sum(sum(result~=inf)) ~= 0
    if lowerLim ~= upperLim & ~isempty(upperLim)
        upperLimTweaked = upperLim + 0.02*(abs(upperLim-lowerLim));
        set(gca, 'CLim', [lowerLim upperLimTweaked]);
    else
        set(gca, 'CLim', [0 inf]);
    end
    set(gca, 'PlotBoxAspectRatio', [1 1 1]);
    xlabel('micrometers');
    ylabel('micrometers');
    text(plotNameTxtPos(1), plotNameTxtPos(2),'Peak', ...
        'Units', 'Normalized', 'FontWeight', 'Bold');
    try
        colorbar('vert');
        text(colorBarTxtPos(1), colorBarTxtPos(2),'pA', 'Units', 'Normalized');
    catch
        disp('array2Dplot: unable to make colorbar for image.');
    end
end

% genMean map
plotnum = plotnum+1;
if ~isempty(find(handles.data.map.mapActive.edBinary));
    hsub(plotnum) = subplot(subplotRows,subplotCols,plotnum);
    genMap = handles.data.map.mapActive.mapDataArray(:,:,9);
    edMap = handles.data.map.mapActive.mapDataArray(:,:,3)==0;
    edGenMap = genMap.*~edMap;
    result = edGenMap;
    result(result==0) = plotPolarityFactor * inf;;
    imagesc(result, 'XData', [-magFacX magFacX], 'YData', [-magFacY magFacY]);
    % lowerLim = min(min(result));
    lowerLim = min(min(result(result>-inf)));
    upperLim = max(max(result(result<inf)));
    %     if sum(sum(result~=inf)) ~= 0
    if lowerLim ~= upperLim & ~isempty(upperLim)
        upperLimTweaked = upperLim + 0.02*(abs(upperLim-lowerLim));
        set(gca, 'CLim', [lowerLim upperLimTweaked]);
    else
        set(gca, 'CLim', [0 inf]);
    end
    set(gca, 'PlotBoxAspectRatio', [1 1 1]);
    xlabel('micrometers');
    text(plotNameTxtPos(1), plotNameTxtPos(2),'Mean', ...
        'Units', 'Normalized', 'FontWeight', 'Bold');
    try
        colorbar('vert');
        text(colorBarTxtPos(1), colorBarTxtPos(2),'pA', 'Units', 'Normalized');
    catch
        disp('array2Dplot: unable to make colorbar for image.');
    end
end

% genOnset map
plotnum = plotnum+1;
if ~isempty(find(handles.data.map.mapActive.edBinary));
    hsub(plotnum) = subplot(subplotRows,subplotCols,plotnum);
    if strcmp(handles.data.analysis.eventPolaritySyn, 'down')
        genMap = handles.data.map.mapActive.mapDataArray(:,:,10);
    else
        genMap = handles.data.map.mapActive.mapDataArray(:,:,12);
    end
    edMap = handles.data.map.mapActive.mapDataArray(:,:,3)==0;
    edGenMap = genMap.*~edMap;
    edGenMap(edGenMap==0) = inf;
    result = edGenMap;
    result(result==0) = plotPolarityFactor * inf;;
    imagesc(result, 'XData', [-magFacX magFacX], 'YData', [-magFacY magFacY]);
    % lowerLim = min(min(result));
    lowerLim = min(min(result(result>-inf)));
    upperLim = max(max(result(result<inf)));
    if lowerLim ~= upperLim & ~isempty(upperLim)
        upperLimTweaked = upperLim + 0.02*(abs(upperLim-lowerLim));
        set(gca, 'CLim', [lowerLim upperLimTweaked]);
    else
        set(gca, 'CLim', [0 inf]);
    end
    set(gca, 'PlotBoxAspectRatio', [1 1 1]);
    xlabel('micrometers');
    text(plotNameTxtPos(1), plotNameTxtPos(2),'Onset', ...
        'Units', 'Normalized', 'FontWeight', 'Bold');
    try
        colorbar('vert');
        text(colorBarTxtPos(1), colorBarTxtPos(2), '(sec)', 'Units', 'Normalized');
    catch
        disp('array2Dplot: unable to make colorbar for image');
    end
end

% ******************************************************************************

colormap(jet2);
if strcmp(handles.data.analysis.eventPolaritySyn, 'down')
    colormap(flipud(colormap(jet2)));
end

% text -- expt name, map number
try
    slashInds = findstr(handles.data.map.mapActive.directory, '\');
    mapNum = handles.data.map.mapActive.directory(( slashInds(end)+1) : end );
    titleStr = [handles.data.analysis.experimentName ', ' mapNum];
    
    text('String', titleStr, 'Units', 'Normalized', 'Position', [0 1.2], ...
        'FontWeight', 'Bold', 'Parent', hsub(1), 'Interpreter', 'none');
    
catch
    disp('array2Dplot: no title display implemented yet');
end


text('String', 'All', 'Units', 'Normalized', 'Position', [-.5 0.3], ...
    'FontWeight', 'Bold', 'Parent', hsub(9), 'Rotation', 90);

text('String', 'Non-Direct', 'Units', 'Normalized', 'Position', [-.5 0.35], ...
    'FontWeight', 'Bold', 'Parent', hsub(13), 'Rotation', 90);

if length(hsub) > 16
    text('String', 'Direct', 'Units', 'Normalized', 'Position', [-.5 0.4], ...
        'FontWeight', 'Bold', 'Parent', hsub(17), 'Rotation', 90);
end
